home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
docume1a
/
docproce
next >
Wrap
Text File
|
1999-09-10
|
20KB
|
601 lines
Attribute VB_Name = "DocProcedures"
'Functions of the document application
'Save Functions, Close Functions, and Exit
'Functions. Created so that frmOpenDoc
'can call the functions, instead of making
'them public in the MDIForm.
'SAVE PROCEDURES
'===============
Public Function SaveEnabled()
If boolnew = False Then
MDIForm1.mnuSave.Enabled = True
MDIForm1.Toolbar1.Buttons(3).Enabled = True
MDIForm1.mnuSaveAs.Enabled = True
MDIForm1.Toolbar1.Buttons(4).Enabled = True
Else
MDIForm1.mnuSaveAs.Enabled = True
MDIForm1.Toolbar1.Buttons(4).Enabled = True
End If
End Function
Public Function SaveDisabled()
MDIForm1.mnuSaveAs.Enabled = False
MDIForm1.mnuSave.Enabled = False
MDIForm1.Toolbar1.Buttons(3).Enabled = False
MDIForm1.Toolbar1.Buttons(4).Enabled = False
End Function
Public Function SaveDoc()
If GetAttr(MDIForm1.CommonDialog1.filename) And vbReadOnly Then
MsgBox MDIForm1.CommonDialog1.filename & " is a read only file. It cannot be saved."
bCannotSave = True
Exit Function
End If
If boolnew = True Then
frmOpenDoc.RichTextBox1.SelStart = 0
frmOpenDoc.RichTextBox1.SaveFile MDIForm1.CommonDialog2.filename
boolsave = True
MDIForm1.mnuSave.Enabled = False
MDIForm1.Toolbar1.Buttons(3).Enabled = False
Else
frmOpenDoc.RichTextBox1.SelStart = 0
frmOpenDoc.RichTextBox1.SaveFile MDIForm1.CommonDialog1.filename
boolsave = False
MDIForm1.mnuSave.Enabled = True
MDIForm1.Toolbar1.Buttons(3).Enabled = False
End If
End Function
Public Function SaveNew()
On Error GoTo ErrHandler
MDIForm1.CommonDialog2.Flags = &H2 'File exists
MDIForm1.CommonDialog2.ShowSave
frmOpenDoc.RichTextBox1.SaveFile MDIForm1.CommonDialog2.filename
boolsave = False
ControlsDisabled
Exit Function
ErrHandler:
Cancel = True
End Function
Public Function SaveAs()
On Error GoTo ErrHandler
MDIForm1.CommonDialog2.Flags = &H2 'File exists
MDIForm1.CommonDialog2.ShowSave
frmOpenDoc.RichTextBox1.SaveFile MDIForm1.CommonDialog2.filename
boolsave = False
boolnew = False
frmOpenDoc.Caption = MDIForm1.CommonDialog2.filename
MDIForm1.StatusBar1.Panels(1).Text = MDIForm1.CommonDialog2.filename
MDIForm1.mnuPrintPreview.Enabled = True: MDIForm1.Toolbar1.Buttons(7).Enabled = True
MDIForm1.mnuDelete.Enabled = True: MDIForm1.Toolbar1.Buttons(5).Enabled = True
Exit Function
ErrHandler:
Cancel = True
End Function
'CLOSING PROCEDURES
'==================
Public Function CloseNew()
Response = MsgBox(" Do You Want To Save Changes?", vbQuestion + vbYesNoCancel)
MDIForm1.CommonDialog2.CancelError = True
On Error GoTo ErrHandler
Select Case Response
Case vbYes
Call SaveAs
Call CloseNew1
Case vbNo
Call ControlsDisabled
Call CloseNew1
End Select
Exit Function
ErrHandler:
Cancel = True
End Function
Public Function CloseModExisting()
If boolsave = True Then
Response = MsgBox(" Do You Want To Save Changes ", vbQuestion + vbYesNoCancel)
On Error GoTo ErrHandler
Select Case Response
Case vbYes
Call SaveDoc
If bCannotSave = False Then
Call CloseModExisting1
End If
Case vbNo
Call CloseModExisting1
End Select
Else
Call ControlsDisabled
frmOpenDoc.RichTextBox1.Visible = False
End If
ErrHandler:
Exit Function
End Function
Public Function CloseFile()
If boolnew = True And boolsave = True Then
Call CloseNew
Else
If boolsave = True Then
Call CloseModExisting
Else
Call ControlsDisabled
frmOpenDoc.RichTextBox1.Visible = False
End If
End If
End Function
'EXIT PROCEDURES
'===============
Public Function ExitDoc()
If boolsave = True And boolnew = True Then
Response = MsgBox(" Do You Want To Save Changes?", vbQuestion + vbYesNoCancel)
MDIForm1.CommonDialog2.CancelError = True
On Error GoTo ErrHandler
Select Case Response
Case vbYes
Call SaveAs
End
Case vbNo
End
End Select
Else
If boolsave = True And boolnew = False Then
Response = MsgBox(" Do You Want To Save Changes?", vbQuestion + vbYesNoCancel)
MDIForm1.CommonDialog2.CancelError = True
On Error GoTo ErrHandler
Select Case Response
Case vbYes
Call SaveDoc
End
Case vbNo
End
End Select
Else
End
End If
End If
ErrHandler:
Exit Function
End Function
'OPEN PROCEDURES
'===============
Public Function OpenDocument()
Call SaveDisabled
Dim currLine&
boolsave = False
boolnew = False
MDIForm1.CommonDialog1.CancelError = True
On Error GoTo ErrHandler
MDIForm1.CommonDialog1.ShowOpen
Screen.MousePointer = 11
DoEvents 'added to hide the Open dialog while loading.
MDIForm1.StatusBar1.Panels(1).Text = "Loading file, please wait..."
frmOpenDoc.Visible = True
frmOpenDoc.RichTextBox1.Visible = True
frmOpenDoc.WindowState = 0
frmOpenDoc.Width = Screen.Width * 0.89 ' Set width of form.
frmOpenDoc.Height = Screen.Height * 0.61 ' Set height of form.
frmOpenDoc.RichTextBox1.LoadFile MDIForm1.CommonDialog1.filename
DoEvents
currLine& = SendMessageLong(frmOpenDoc.RichTextBox1.hwnd, EM_LINEFROMCHAR, -1&, 0&) + 1
MDIForm1.StatusBar1.Panels(4) = Format$(currLine&, "##,###")
MDIForm1.StatusBar2.Visible = False
frmOpenDoc.Caption = MDIForm1.CommonDialog1.filename
frmOpenDoc.SetFocus
MDIForm1.StatusBar1.Panels(1) = MDIForm1.CommonDialog1.filename
Screen.MousePointer = 0
Call ControlsEnabled
frmFind.Hide
frmReplace.Hide
boolnew = False
Exit Function
ErrHandler:
Exit Function
End Function
Public Function OpenDocMod()
Response = MsgBox(" Do You Want To Save Changes?", vbQuestion + vbYesNoCancel)
MDIForm1.CommonDialog2.CancelError = True
On Error Resume Next
Select Case Response
Case vbYes
OpenDocModify
Case vbNo
ControlsDisabled
frmOpenDoc.Visible = False
Call OpenFile
End Select
frmFind.Hide
frmReplace.Hide
Exit Function
ErrHandler:
Exit Function
End Function
Public Function OpenFile()
If boolnew = True And boolsave = True Then
Call OpenDocMod
Else
If boolsave = True Then
Call OpenCloseModExisting
Else
Call OpenDocument
End If
End If
End Function
Public Function OpenCloseModExisting()
If boolnew = True And boolsave = True Then
Call OpenDocMod
Else
If boolsave = True Then
Response = MsgBox(" Do You Want To Save Changes?", vbQuestion + vbYesNoCancel)
On Error GoTo ErrHandler
Select Case Response
Case vbYes
Call SaveDoc
Call OpenDocument
Case vbNo
Call OpenDocument
End Select
Else
Call OpenDocument
End If
frmFind.Hide
frmReplace.Hide
End If
Exit Function
ErrHandler:
Exit Function
End Function
Public Function DocUnload()
If boolnew = True And boolsave = True Then